/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gen2phen.labs.actions;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.UrlBinding;
import org.gen2phen.labs.domain.Drug;
import org.gen2phen.labs.services.Loader;

/**
 *
 * @author pedrolopes
 *
 * GEN2PHEN Semantic Web Labs: Knowledge Netowork
 *
 */
@UrlBinding("/drug/{$event}/{query}")
public class DrugActionBean implements ActionBean {

    private ActionBeanContext context;
    private String query;
    private Drug drug;

    public Drug getDrug() {
        return drug;
    }

    public void setDrug(Drug drug) {
        this.drug = drug;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public ActionBeanContext getContext() {
        return context;
    }

    /**
     * Get given Drug information.
     *
     * @return Result string to be processed by client-side JavaScript
     */
    @DefaultHandler
    public Resolution get() {
        String html = "";

        drug = Loader.getDrugs().get(query);    // use loader to get info from cached results

        // write full result string
        html += drug.getName() + "#" + drug.getDescription() + "#" + drug.getIndication() + "#" + drug.getPharma();
        return new StreamingResolution("text", html);
    }
}
